<?php
/**
 * Index.php
 * Niushop商城系统 - 团队十年电商经验汇集巨献!
 * =========================================================
 * Copy right 2015-2025 山西牛酷信息科技有限公司, 保留所有权利。
 * ----------------------------------------------
 * 官方网址: http://www.niushop.com.cn
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用。
 * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
 * =========================================================
 * @author : niuteam
 * @date : 2015.1.17
 * @version : v1.0.0.0
 */

namespace app\agent\controller;

use addons\Nsfx\data\service\NfxGoods;
use addons\Nsfx\data\service\NfxRegionAgentApply;

/**
 * 数据
 */
class Stat extends BaseController
{
	public function index()
	{
        $nfx_goods = new NfxGoods();
        $category_list = $nfx_goods->getRegionAgentCategory($this->uid);
        $this->assign('category_list', $category_list);

        $nfx_region_agent_apply = new NfxRegionAgentApply();
        $address_list = $nfx_region_agent_apply->getRegionAgentAddress($this->uid);
        $this->assign('address_list', $address_list);

		return view($this->style . 'Stat/index');
	}

    public function goods()
    {
        if(request()->isAjax()){
            $page_index = input('page_index', 1);
            $page_size = input('page_size', PAGESIZE);
            $category_id = input('category_id', 0);

            $params = [];
            $params['uid'] = $this->uid;
            if($category_id != 0){
                $params['category_id'] = $category_id;
            }

            $nfx_goods = new NfxGoods();
            $res = $nfx_goods->getRegionAgentCategoryGoods($params, $page_index, $page_size);
            return $res;
        }else{
            $nfx_goods = new NfxGoods();
            $category_list = $nfx_goods->getRegionAgentCategory($this->uid);
            $this->assign('category_list', $category_list);

            return view($this->style . 'Stat/goods');
        }
    }

    public function promoter()
    {
        if(request()->isAjax()){
            $page_index = input('page_index', 1);
            $page_size = input('page_size', PAGESIZE);
            $goods_id = input('goods_id', 0);

            $params = [];
            $params['uid'] = $this->uid;
            $params['goods_id'] = $goods_id;

            $nfx_goods = new NfxGoods();
            $res = $nfx_goods->getPromoterGoodsLowerPromoter($params, $page_index, $page_size);
            return $res;
        }else{
            $goods_id = request()->get('goods_id', 0);
            $this->assign('goods_id', $goods_id);

            $nfx_goods = new NfxGoods();
            $res = $nfx_goods->getRegionAgentCategoryGoods(['uid' => $this->uid, 'goods_id' => $goods_id], 1, 0);
            $goods_info = $res['data'][0];
            $this->assign('goods_info', $goods_info);

            return view($this->style . 'Stat/promoter');
        }

    }
}